//
//  PaymentFooterView.swift
//  LeTu
//
//  Created by gy on 2024/1/10.
//

import UIKit

class PaymentFooterView: UIView {

    init(target: Any?, action: Selector) {
        super.init(frame: .zero)
        
        configUI()
        payBtn.addTarget(target, action: action)

    }
    override func layoutSubviews() {
        super.layoutSubviews()
        DispatchQueue.main.async {
            self.payBtn.layerCornerRadius(self.payBtn.height/2)
        }
    }
    static func getViewHeight() -> CGFloat {
        return 119
    }
    func updatePrice(_ price: String) {
        priceLabel.isHidden = price == "0"
        priceLabel.text = "实付金额：¥".localized + "\(price)"
    }
    
    // MARK: - configUI
    func configUI() {
        
        backgroundColor = .app_white
        addSubview(safeView)
        addSubview(backView)
        backView.addSubview(contentView)
        contentView.addSubview(priceLabel)
        contentView.addSubview(payBtn)
        
        safeView.snp.makeConstraints { make in
            make.left.bottom.right.equalToSuperview()
            make.height.equalTo(34)
        }
        backView.snp.makeConstraints { make in
            make.top.equalToSuperview()
            make.bottom.equalTo(safeView.snp.top)
            make.left.equalTo(22)
            make.right.equalTo(-22)
        }
        contentView.snp.makeConstraints { make in
            make.left.right.centerY.equalToSuperview()
        }
        priceLabel.snp.makeConstraints { make in
            make.left.top.right.equalToSuperview()
        }
        payBtn.snp.makeConstraints { make in
            make.left.bottom.right.equalToSuperview()
            make.top.equalTo(priceLabel.snp.bottom).offset(4)
            make.height.equalTo(CGFloat.app_btnHeight)
        }
        
    }
    private lazy var safeView = UIView()
    private lazy var backView: UIView = {
        let backView = UIView()
        return backView
    }()
    private lazy var contentView = UIView()
    private var priceLabel: UILabel = {
        let priceLabel = UILabel()
        priceLabel.font = kSetPingFangRegular(14)
        priceLabel.textColor = UIColor.hex(hexString: "868D9A")
        return priceLabel
    }()
    private lazy var payBtn: GradientButton = {
        let payBtn = GradientButton()
        payBtn.gradientColors = UIColor.app_themeGradientColors
        payBtn.setFont(kSetPingFangMedium(16))
        payBtn.setTitle("立即支付".localized)
        return payBtn
    }()
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}
